package cc.minos.servers.openfire.ui.textbox
{
	import cc.minos.servers.openfire.chats.ChatMessage;
	import cc.minos.servers.openfire.filters.MessageFilter;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import flashx.textLayout.elements.FlowElement;
	import flashx.textLayout.elements.ParagraphElement;
	import flashx.textLayout.elements.SpanElement;
	
	/**
	 * ...
	 * @author Minos
	 */
	public class DynamicTextFlow extends TextBox implements IChatUI
	{
		private var timer:Timer;
		
		public function DynamicTextFlow( width:Number = 100 , height:Number = 100 )
		{
			_manager = new CustomSelectionManager();
			super( width , height , DYNAMIC );
			
			timer = new Timer( 20 , 20 );
			timer.addEventListener( TimerEvent.TIMER , function():void
				{
					scrollV = maxScrollV;
				} );
		}
		
		/* INTERFACE cc.minos.servers.openfire.ui.textbox.interfaces.IChatUI */
		
		public function addMessage( message:ChatMessage ):void
		{
			var div:FlowElement = MessageFilter.changeToIM( message );
			if ( div )
			{
				_flow.addChild( div );
				update();
				_scroll.scrollToEnd();
			}
		}
		
		public function addSystemMessage( body:String ):void
		{
			//return;
			var span:SpanElement = new SpanElement();
			span.text = body;
			var p:ParagraphElement = new ParagraphElement();
			p.addChild( span );
			p.color = "0x" + MessageFilter.systemColor;
			_flow.addChild( p );
			update();
		}
	
	}

}